<template>
  <div>
    <el-row>
      <el-card style="margin-top: 20px">
        <el-col>
          <el-button @click="Tanchuan('add')" type="primary" size="medium"
            >添加工作模式</el-button
          >
        </el-col>
        <el-col>
          <el-table
            border
            stripe
            style="text-align: center; margin-top: 15px; margin-bottom: 20px"
            :data="tableDate"
          >
            <el-table-column label="工作模式编号" prop="id"></el-table-column>
            <el-table-column prop="name" label="工作模式"></el-table-column>
            <el-table-column
              prop="workPatternTypeDesc"
              label="类型"
            ></el-table-column>
            <el-table-column prop="workDate" label="工作日期"></el-table-column>
            <el-table-column label="工作时间">
              <template #default="{ row }">
                {{
                  `${((row.workEndMinute1 - row.workStartMinute1) / 60).toFixed(
                    2
                  )}小时`
                }}
              </template>
            </el-table-column>
            <el-table-column label="操作" width="210">
              <template #default="{ row }">
                <el-button
                  @click="Tanchuan('edit', row)"
                  style="color: deepskyblue"
                  type="text"
                  >编辑</el-button
                >
                <span style="margin: 7px; color: #ccc">|</span>
                <el-button style="color: red" type="text">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination
            style="margin-bottom: 20px"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="this.page.page"
            :page-sizes="[10, 20, 30, 50]"
            :page-size="this.page.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
          >
          </el-pagination>
        </el-col>
      </el-card>
    </el-row>
    <el-dialog @close="close" :visible="isDone" :title="title">
      <el-tabs style="margin-left: 40px" v-model="activeName">
        <el-tab-pane v-if="LiDone" label="礼拜制" name="first">
          <el-form>
            <el-form-item label="工作模式名称：">
              <el-input
                placeholder="请填写工作模式名称"
                style="width: 400px"
              ></el-input>
            </el-form-item>
            <el-form-item label="连续工作天数：">
              <el-checkbox-group v-model="checkList">
                <el-checkbox label="周一"></el-checkbox>
                <el-checkbox label="周二"></el-checkbox>
                <el-checkbox label="周三"></el-checkbox>
                <el-checkbox label="周四"></el-checkbox>
                <el-checkbox label="周五"></el-checkbox>
                <el-checkbox label="周六"></el-checkbox>
                <el-checkbox label="周日"></el-checkbox>
              </el-checkbox-group>
            </el-form-item>
            <el-form-item label="工作时间：">
              <el-time-picker
                is-range
                v-model="value1"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围"
              >
              </el-time-picker>
            </el-form-item>
          </el-form>
        </el-tab-pane>
        <el-tab-pane v-if="LianDone" label="连续制" name="second">
          <el-form>
            <el-form-item label="工作模式名称：">
              <el-input
                placeholder="请填写工作模式名称"
                style="width: 400px"
              ></el-input>
            </el-form-item>
            <el-form-item label="连续工作天数：">
              <span style="margin-right: 10px">上</span>
              <el-input
                style="width: 100px; margin-right: 7px"
                placeholder="请输入"
                type="text"
                suffix="天"
              ></el-input>
              <span style="margin-right: 10px">休</span>
              <el-input
                style="width: 100px; margin-right: 7px"
                placeholder="请输入"
              ></el-input>
            </el-form-item>
            <el-form-item label="工作时间：">
              <el-time-picker
                is-range
                v-model="value1"
                range-separator="至"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                placeholder="选择时间范围"
              >
              </el-time-picker>
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>
      <el-row type="flex" justify="center">
        <el-button type="primary">确定</el-button>
        <el-button @click="close" style="margin-left: 50px">取消</el-button>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { getPaiBanListApi } from "@/api/employee";

export default {
  data() {
    return {
      tableDate: [],
      isDone: false,
      LianDone: true,
      LiDone: true,
      title: "新增工作模式",
      total: 0,
      activeName: "first",
      checkList: [],
      value1: [new Date(2023, 3, 8, 9, 0), new Date(2023, 3, 8, 18, 0)],
      page: {
        page: 1,
        pageSize: 10,
      },
    };
  },
  created() {
    this.getPaiBanListInfo();
  },
  methods: {
    close() {
      this.isDone = false;
    },
    Tanchuan(type, date) {
      this.isDone = true;
      if (type === "edit") {
        this.title = "编辑工作模式";
        if (date.workPatternTypeDesc === "连续制") {
          this.LianDone = true;
          this.LiDone = false;
          this.activeName = "second";
        } else if (date.workPatternTypeDesc === "礼拜制") {
          this.LianDone = false;
          this.LiDone = true;
          this.activeName = "first";
        }
        return;
      }
      this.LianDone = true;
      this.LiDone = true;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.page.pageSize = val;
      this.getCheMessageInfo();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.page.page = val;
      this.getCheMessageInfo();
    },
    async getPaiBanListInfo() {
      const res = await getPaiBanListApi(this.page);
      console.log(res.data.data);
      this.tableDate = res.data.data.items;
      this.total = +res.data.data.counts;
    },
  },
};
</script>

<style lang="scss" scoped>
.el-pagination {
  text-align: center;
}
.el-form {
  ::v-deep .el-form-item__label {
    width: 110px;
  }
}
</style>
